<?php
/*
Extension Name: Auto Hide
Extension Url: http://software.lordmatt.com
Description: A role-based moderation scheme that auto-hides any new post and/or discussion entered by affected users, and provides moderators with a screening page accessible from the panel.
Version: 0.1.1
Author: Matt Brown
Author Url: http://lordmatt.com/?page_id=17
*/

$Context->Dictionary['PERMISSION_AUTO_HIDE'] = 'Auto-hide all comments and discussions.';
$Context->Dictionary['PERMISSION_MODERATE_AUTO_HIDES'] = 'Moderate auto-hidden comments and discussions.';
$Context->Dictionary['AutoHide_ModerationPanelListName'] = 'Auto-Hide Moderation';
$Context->Dictionary['AutoHide_CommentModerationLink'] = 'Moderate Items';
$Context->Dictionary['AutoHide_ErrorCountingHiddenComments'] = 'Unable to get a count of comments needing moderation.';
$Context->Dictionary['AutoHide_ErrorRemovingPermissions'] = 'Unable to remove the permissions used by this extension.';
$Context->Dictionary['AutoHide_ErrorHidingComment'] = 'There was an error entering your comment.';
$Context->Dictionary['AutoHide_ErrorHidingDiscussion'] = 'There was an error starting your discussion.';
$Context->Dictionary['AutoHide_ErrorGettingCommentsForModeration'] = 'Unable to retrieve the list of comments needing moderation.';
$Context->Dictionary['AutoHide_UserNotice'] = 'Auto-hiding is active for your user group.  All new discussions, new comments, and comment edits are screened by a moderator prior to display.  Please be patient while we make sure you\'re not a spammer.';
$Context->Dictionary['AutoHide_DiscussionModerationHeading'] = 'Auto-hidden Discussions';
$Context->Dictionary['AutoHide_CommentModerationHeading'] = 'Auto-hidden Comments';
$Context->Dictionary['AutoHide_AutoHideRoleNotice'] = 'Auto Hide tip: Users whose submissions are auto-hidden should not have permission to delete comments/discussions, or view deleted comments/discussions.';
$Context->Dictionary['AutoHide_AutoHideModerationRoleNotice'] = 'Auto Hide tip: Users with permission to moderate auto-hidden content should also have permission to edit comments/discussions and view deleted comments/discussions.';

// Create default values for the new permissions.
CreateArrayEntry($Configuration, 'PERMISSION_AUTO_HIDE', 0);
CreateArrayEntry($Configuration, 'PERMISSION_MODERATE_AUTO_HIDES', 0);

// Bring in the role utility functions used by this extension.
include("role_utilities.php");

// Bring in the extension-disable handler (always active).
include("on_disable.php");

// Bring in the comment/discussion filter delegates (always active).
include("delegate_comment_filters.php");

// If we're on the settings page, register our permissions.
if ($Context->SelfUrl == "settings.php"){
   include("delegate_autohide_permissions.php");
   include("AutoHide.Control.RoleEditNotice.php");
   $RoleEditNotice = $Context->ObjectFactory->NewContextObject($Context,
   	'RoleEditNotice');
   $Page->AddRenderControl($RoleEditNotice, $Configuration["CONTROL_POSITION_BODY_ITEM"] + 1);
}

// For affected users, add a notice to the post page that all comments are hidden.
if (($Context->Session->User->Permission('PERMISSION_AUTO_HIDE'))
	&& (($Context->SelfUrl == "post.php") || ($Context->SelfUrl == "comments.php"))){
   $NoticeCollector->AddNotice($Context->GetDefinition('AutoHide_UserNotice'));
}

// Bring in the moderation tools, if the user is a moderator.
if ($Context->Session->User->Permission('PERMISSION_MODERATE_AUTO_HIDES')){
   // Show the auto-hide moderation panel.
   include("autohide_panel.php");
   // Add in the moderation-list control if we're on the extension page.
   if ($Context->SelfUrl == "extension.php"){
      include("AutoHide.Control.ModerationList.php");
      include("delegate_discussion_search.php");
      $ModerationList = $Context->ObjectFactory->NewContextObject($Context, 'ModerationList');
      ModerationList::$RoleIDs = GetRoleIDsWithPermission($Context,'PERMISSION_AUTO_HIDE');
      $ModerationList->PopulateList();
      $Page->AddRenderControl($ModerationList, $Configuration["CONTROL_POSITION_BODY_ITEM"] + 1);
   }
}

?>
